package com.woniuxy.store.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.cloud.mall95.log.Log;
import com.woniuxy.food.client.foodspuclient.FoodSpuManageClient;
import com.woniuxy.food.client.foodspuclient.FoodSpuQueryClient;
import com.woniuxy.food.client.foodtypespuclient.FoodTypeSpuManageClient;
import com.woniuxy.food.client.param.*;
import com.woniuxy.store.app.util.StoreIdUtil;
import com.woniuxy.store.client.FoodClient;
import com.woniuxy.store.client.param.foodParam.*;
import common.WoniuPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import result.Result;

import javax.validation.Valid;

@RestController
@RequestMapping("/store/food")
public class FoodClientImpl implements FoodClient {

    @Autowired
    private FoodSpuManageClient foodSpuManageClient;

    @Autowired
    private FoodSpuQueryClient foodSpuQueryClient;

    @Autowired
    private FoodTypeSpuManageClient foodTypeSpuManageClient;

    @Override
    @Log("添加菜品spu")
    public Result insertFoodSpu(@Valid InsertFoodSpuParams var1) {
        InsertFoodSpuParam param = BeanUtil.toBean(var1, InsertFoodSpuParam.class);
        param.setStoreId(StoreIdUtil.getFromToken());
        return foodSpuManageClient.insertFoodSpu(param);
    }

    @Override
    @Log("修改菜品spu的状态")
    public Result updateFoodSpuStateByIds(@Valid UpdateFoodSpuStateParams var1) {
        UpdateFoodSpuStateParam param = BeanUtil.toBean(var1, UpdateFoodSpuStateParam.class);
        param.setStoreId(StoreIdUtil.getFromToken());
        return foodSpuManageClient.updateFoodSpuStateByIds(param);
    }

    @Override
    @Log("修改菜品spu信息")
    public Result updateFoodSpuById(@Valid UpdateFoodSpuParams var1) {
        UpdateFoodSpuParam param = BeanUtil.toBean(var1, UpdateFoodSpuParam.class);
        param.setStoreId(StoreIdUtil.getFromToken());
        return foodSpuManageClient.updateFoodSpuById(param);
    }

    @Override
    @Log("修改菜品spu总销量")
    public Result updateFoodSpuSalesCountById(@Valid UpdateFoodSpuSalesCountParams var1) {
        UpdateFoodSpuSalesCountParam param = BeanUtil.toBean(var1, UpdateFoodSpuSalesCountParam.class);
        param.setStoreId(StoreIdUtil.getFromToken());
        return foodSpuManageClient.updateFoodSpuSalesCountById(param);
    }

    @Override
    @Log("批量删除菜品spu")
    public Result deleteFoodSpuByIds(Integer[] var2) {
        return foodSpuManageClient.deleteFoodSpuByIds(StoreIdUtil.getFromToken(),var2);
    }

    @Override
    @Log("根据条件查询菜品spu")
    public Result searchFoodSpuByCondition(@Valid SearchFoodSpuByConditionParams var1) {
        SearchFoodSpuByConditionParam param = BeanUtil.toBean(var1, SearchFoodSpuByConditionParam.class);
        param.setStoreId(StoreIdUtil.getFromToken());
        return foodSpuQueryClient.searchFoodSpuByCondition(param);

    }

    @Override
    @Log("额外添加菜品spu的类型")
    public Result insertFoodTypeSpu(InsertFoodTypeSpuParams param) {
        InsertFoodTypeSpuParam insertFoodTypeSpuParam = BeanUtil.toBean(param, InsertFoodTypeSpuParam.class);
        insertFoodTypeSpuParam.setStoreId(StoreIdUtil.getFromToken());
        return foodTypeSpuManageClient.insertFoodTypeSpu(insertFoodTypeSpuParam);
    }
}
